import {observable,computed,action} from 'mobx';
import {getShopList} from '../../api/shop';

class Shop{
    @observable price = 100;
    @observable count = 1;
    @observable shoplist = [];

    @computed get total(){
        return this.shoplist.reduce((prev,cur) => {
            return prev+= cur.price * cur.count
        },0)
    }

    @action
    getShopList = async () => {
        let res = await getShopList();
        console.log(res);
        this.shoplist = res.data.data;
    }

    @action
    changeCount = (flag,id) => {
        //true + false -   id:索引
        this.shoplist[id].count = flag ? this.shoplist[id].count + 1 : this.shoplist[id].count - 1;
    }

}

export default new Shop()
